<template>
  <div class="scrollbox">
    <!-- 头部 -->
    <v-header></v-header>
    <div class="dis10"></div>
    <div class="listbox aps8">
      <v-list api="user.get_login_log" ref="list" cards="1" cols="230,300,0,150" :params="params">
        <template slot="search">
          &nbsp;&nbsp;&nbsp;
          <span class="fr"></span>
        </template>
        <template slot="head" slot-scope="props">
          <thead>
            <tr class="tr">
              <th class="c1">账户ID</th>
              <th>详情</th>
              <th>登录IP</th>
              <th>时间</th>
            </tr>
          </thead>
        </template>
        <template slot="item" slot-scope="props">
          <tr>
            <td>
              {{ props.item.uname }}
              <span class="font-gray2">[{{ props.item.uid }}]</span>
            </td>
            <td class="font-gray">{{props.item.log_data}}</td>
            <td class="font-gray">{{props.item.log_ip}}</td>
            <td class="font-gray">{{props.item.dateline | dateFormat('yyyy-MM-dd HH:mm')}}</td>
          </tr>
        </template>
      </v-list>
    </div>

    <!-- 编辑 -->
    <el-dialog :title="editData.title" :visible.sync="editData.status" width="680px" top="7vh">
      <div class="dialogform">
        <el-form
          :model="form"
          :rules="rules"
          ref="form"
          label-width="120px"
          label-position="right"
          class="demo-ruleForm"
        >
          <el-form-item label="联盟编码" prop="union_id">
            <el-input :disabled="form.id > 0" v-model="form.union_id" class="w200"></el-input>
          </el-form-item>
          <el-form-item label="联盟名称" prop="name">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item label="绑定域名">
            <el-input v-model="form.domain" type="textarea" rows="6"></el-input>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark"></el-input>
          </el-form-item>
          <el-form-item label="排序" prop="sort">
            <el-input v-model="form.sort" class="w200"></el-input>
          </el-form-item>
          <el-form-item label prop="inlock">
            <el-button type="primary" @click="save">保 存</el-button>
            <el-button @click="editData.status = false">取 消</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="tc"></div>
    </el-dialog>
    <!-- 编辑结束 -->
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        id: "",
        name: "",
        union_id: "",
        domain: "",
        remark: "",
        sort: 0
      },
      editData: {
        status: false,
        title: "新增/修改联盟",
        id: 0
      },
      rules: {
        union_id: [
          {
            type: "string",
            required: true,
            message: "请输入联盟编码",
            trigger: "blur"
          },
          { min: 1, message: "联盟编码不能为空", trigger: "blur" }
        ],
        name: [
          {
            type: "string",
            required: true,
            message: "请输入联盟名称",
            trigger: "blur"
          },
          { min: 1, message: "联盟名称不能为空", trigger: "blur" }
        ]
      },
      params: {},
      cols: "200,110,0,130,120",
      menu: [{ key: "sys", value: "系统" }, { key: "console", value: "控制台" }]
    };
  },
  methods: {
    edit(item) {
      this.editData.status = true;
      this.editData.id = item.id || 0;
      this.form.id = this.editData.id;
      this.form.union_id = item.union_id || "";
      this.form.name = item.name || "";
      this.form.domain = item.domain || "";
      this.form.remark = item.remark || "";
      this.form.sort = item.sort || 0;
    },
    save() {
      let that = this;
      that.$refs["form"].validate(valid => {
        if (valid) {
          let url =
            that.editData.id > 0
              ? "system.modify_sys_union"
              : "system.add_sys_union";
          that.$api.post(url, that.form).then(res => {
            if (res.status === 1) {
              this.$success(res.msg);
              that.$refs.list.fetchData();
              that.editData.status = false;
            } else {
              that.$error(res.msg);
            }
          });
        }
      });
    },
    // 刷新缓存
    refresh() {
      this.$api.get("system.refresh_sys_union").then(res => {
        if (res.status === 1) {
          this.$success(res.msg);
          this.$refs.list.fetchData();
        }
      });
    },
    del(row) {
      let that = this;
      that
        .$confirm("此操作会将该彻底删除，不可恢复, 是否继续?", "删除提醒")
        .then(() => {
          that.$api
            .post("system.delete_sys_union", { id: row.id })
            .then(res => {
              if (res.status === 1) {
                that.$success(res.msg);
                that.$refs.list.fetchData();
              } else {
                that.$error(res.msg);
              }
            });
        })
        .catch(() => {});
    }
  },
  mounted() {}
};
</script>

<style lang="scss" scoped>
.tabs {
  width: 290px;
}
</style>
